<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>闭包的作用</title>
</head>
<body>

</body>
<script>
    // 闭包的作用
    // 可以做缓存 (存储结构)
    // eg : eater
    //
    function eater() {
        var food = "";
        var obj = {
            eat : function (){
                console.log("i am eating " + food);
                food = "";
            },
            push : function (myFood) {
                food = myFood;
            }
        }
        return obj;
    }

    var eater1 = eater();
    eater1.push('apple');
    eater1.eat();

</script>
</html>
